cmake_minimum_required(VERSION 3.28)
set(CMAKE_C_STANDARD 11)
project(INIProject VERSION 1.0)

# 指定源文件
set(SOURCE_FILES src/main.c
        src/main_inih.c
        src/main_iniparser.c
        libs/iniparser/iniparser.h
        libs/iniparser/iniparser.c
        libs/iniparser/dictionary.h
        libs/iniparser/dictionary.c
        libs/inih/ini.c
        libs/inih/ini.h)

# 可执行文件名称参数化(JsonApp为可执行文件名)
set(EXECUTABLE ini_test)
add_executable(${EXECUTABLE} ${SOURCE_FILES})

# 将配置文件从源目录复制到构建目录
set(CONFIG_FILE ${CMAKE_SOURCE_DIR}/etc/config.ini)
configure_file(${CONFIG_FILE} ${CMAKE_BINARY_DIR}/etc/config.ini @ONLY)

# 安装配置文件和可执行文件到目标目录(即执行make install时的安装配置)
# FILES为普通文件,TARGETS是可执行文件或库文件
install(FILES ${CONFIG_FILE} DESTINATION etc)
install(TARGETS ${EXECUTABLE} DESTINATION bin)
